<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
   <?php echo $this->breadCrumbs(); ?>
  </div>
  <?php if (isset($error_warning)) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/product.png" alt="" /> <?php echo $_['heading_title']; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $_['button_save']; ?></a><a href="<?php echo UA('catalog/topic'); ?>" class="button"><?php echo $_['button_cancel']; ?></a></div>
    </div>
    <div class="content">
      <div id="tabs" class="htabs"><a href="#tab-general"><?php echo $_['tab_general']; ?></a><a href="#tab-data"><?php echo $_['tab_data']; ?></a><a href="#tab-design"><?php echo $_['tab_design']; ?></a></div>
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
        <div id="tab-general">
          <div id="languages" class="htabs">
            <?php foreach ($languages as $language_id => $language) { ?>
            <a href="#language<?php echo $language_id; ?>"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> <?php echo $language['name']; ?></a>
            <?php } ?>
          </div>
          <?php foreach ($languages as $language_id => $language) { ?>
          <div id="language<?php echo $language_id; ?>">
            <table class="form">
              <tr>
                <td><span class="required">*</span> <?php echo $_['entry_title']; ?></td>
                <td><input type="text" name="topic_description[<?php echo $language_id; ?>][title]" size="83" value="<?php echo $vo->getL('topic_description', $language_id, 'title'); ?>"  data-rule-required="true" data-rule-rangelength="3,255"/>
                  <?php echo form_error("topic_description[{$language_id}][title]") ?></td>
              </tr>
              <tr>
                <td><?php echo $_['entry_seo_title']; ?></td>
                <td><input type="text" name="topic_description[<?php echo $language_id; ?>][seo_title]" size="83" value="<?php echo $vo->getL('topic_description', $language_id, 'seo_title'); ?>"></td>
              </tr>
              <tr>
                <td><?php echo $_['entry_meta_description']; ?></td>
                <td><textarea name="topic_description[<?php echo $language_id; ?>][meta_description]" cols="80" rows="3"><?php echo $vo->getL('topic_description', $language_id, 'meta_description'); ?></textarea></td>
              </tr>
              <tr>
                <td><?php echo $_['entry_meta_keyword']; ?></td>
                <td><textarea name="topic_description[<?php echo $language_id; ?>][meta_keywords]" cols="80" rows="3"><?php echo $vo->getL('topic_description', $language_id, 'meta_keywords'); ?></textarea></td>
              </tr>
              <tr>
                <td><?php echo $_['entry_description']; ?></td>
                <td><textarea name="topic_description[<?php echo $language_id; ?>][description]" id="description<?php echo $language_id; ?>"><?php echo $vo->getL('topic_description', $language_id, 'description'); ?></textarea></td>
              </tr>
            </table>
          </div>
          <?php } ?>
        </div>
        <div id="tab-data">
          <table class="form">
			<tr>
              <td><?php echo $_['entry_image']; ?></td>
              <td valign="top"><div class="image"><img src="<?php echo thumb($vo->get('image')); ?>" alt="" id="thumb" />
                <input type="hidden" name="image" value="<?php echo $vo->get('image'); ?>" id="image" />
                <br /><a onclick="image_upload('image', 'thumb', '<?php echo $token;?>');"><?php echo $_['text_browse']; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$('#thumb').attr('src', '<?php echo thumb(); ?>'); $('#image').attr('value', '');"><?php echo $_['text_clear']; ?></a></div></td>
            </tr>
			<tr>
              <td><?php echo $_['entry_date_start']; ?></td>
                <td><input type="text" class="date" name="date_start" value="<?php echo $vo->get('date_start'); ?>" /></td>
            </tr>
            <tr>
              <td><?php echo $_['entry_date_end']; ?></td>
                <td><input type="text" class="date" name="date_end" value="<?php echo $vo->get('date_end'); ?>" /></td>
            </tr>
            <tr>
              <td><?php echo $_['entry_status']; ?></td>
              <td><select name="status">
              	<?php echo form_select_option($_['option_statuses'], $vo->get('status', 1) , true);?>
                </select></td>
            </tr>
          </table>
        </div>
        <div id="tab-design">
          <table class="form">
            <tr>
              <td><?php echo $_['entry_template']; ?></td>
              <td><input type="text" name="template" value="<?php echo $vo->get('template'); ?>" size="35" /></td>
            </tr>
          </table>
		  <div id="modules">
          <table class="list">
            <thead>            
              <tr>
                <td class="left"><?php echo $_['column_module']; ?></td>
                <td class="left"><?php echo $_['column_config']; ?></td>
				<td class="left"><?php echo $_['column_sort_order']; ?></td>
				<td></td>
              </tr>
            </thead>
			<?php $module_row = 0; ?>
			<?php foreach ($modules as $module) { ?>
			
			<?php if ($module['type'] == 'banner') { ?>
            <tbody id="module-row<?php echo $module_row;?>">
			  <tr>
				<td>
				  <?php echo $_['text_banner'];?>
				  <input type="hidden" name="module[<?php echo $module_row?>][type]" value="banner">
				</td>
				<td>
				  <?php echo $_['text_banner']?> :
				  <select name="module[<?php echo $module_row?>][data][banner_id]">
				  <?php echo form_select_option($banners, $module['data']['banner_id'], null, 'banner_id', 'name'); ?>
				  </select>
				  &nbsp;&nbsp;
				  <?php echo $_['text_template']?> :
				  <input type="text" name="module[<?php echo $module_row?>][data][template]" value="<?php echo $module['data']['template']?>">
				</td>
				<td><input type="text" name="module[<?php echo $module_row?>][sort_order]" value="<?php echo $module['sort_order'];?>" size="3"></td>
				<td class="left"><a onclick="$('#module-row<?php echo $module_row; ?>').remove();" class="button"><?php echo $_['button_remove']; ?></a></td>
			  </tr>
            </tbody>
			<?php } elseif ($module['type'] == 'slideshow') { ?>
			<tbody id="module-row<?php echo $module_row;?>">
			  <tr>
				<td>
				  <?php echo $_['text_slideshow'];?>
				  <input type="hidden" name="module[<?php echo $module_row?>][type]" value="slideshow">
				</td>
				<td>
				  <?php echo $_['text_banner']?> :
				  <select name="module[<?php echo $module_row?>][data][banner_id]">
				  <?php echo form_select_option($banners, $module['data']['banner_id'], null, 'banner_id', 'name'); ?>
				  </select>
				  &nbsp;&nbsp;
				  <?php echo $_['text_template']?> :
				  <input type="text" name="module[<?php echo $module_row?>][data][template]" value="<?php echo $module['data']['template']?>">
				</td>
				<td><input type="text" name="module[<?php echo $module_row?>][sort_order]" value="<?php echo $module['sort_order'];?>" size="3"></td>
				<td class="left"><a onclick="$('#module-row<?php echo $module_row; ?>').remove();" class="button"><?php echo $_['button_remove']; ?></a></td>
			  </tr>
            </tbody>
			<?php } elseif ($module['type'] == 'product') { ?>
			<tbody id="module-row<?php echo $module_row;?>">
			  <tr>
				<td>
				  <?php echo $_['text_product'];?>
				  <input type="hidden" name="module[<?php echo $module_row?>][type]" value="product">
				</td>
				<td><p><?php echo $_['text_title'];?>:
				  <?php foreach ($languages as $language_id => $language) { ?>
				  <input type="text" name="module[<?php echo $module_row?>][data][title][<?php echo $language_id; ?>]" 
              value="<?php echo $module['data']['title'][$language_id]; ?>" />
              <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" />
				  <?php } ?>
				  </p><p><?php echo $_['text_refid']?> :
				  <input type="text" name="module[<?php echo $module_row?>][data][refid]" value="<?php echo $module['data']['refid']?>">
				  &nbsp;&nbsp;
				  <?php echo $_['text_template']?> :
				  <input type="text" name="module[<?php echo $module_row?>][data][template]" value="<?php echo $module['data']['template']?>">
				  </p>
				</td>
				<td><input type="text" name="module[<?php echo $module_row?>][sort_order]" value="<?php echo $module['sort_order'];?>" size="3"></td>
				<td class="left"><a onclick="$('#module-row<?php echo $module_row; ?>').remove();" class="button"><?php echo $_['button_remove']; ?></a></td>
			  </tr>
            </tbody>
			<?php } elseif ($module['type'] == 'custom') { ?>
			<tbody id="module-row<?php echo $module_row;?>">
			  <tr>
				<td>
				  <?php echo $_['text_custom'];?>
				  <input type="hidden" name="module[<?php echo $module_row?>][type]" value="product">
				</td>
				<td valign="top">
				<?php foreach ($languages as $language_id => $language) { ?>
				  <p><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" />
				  <textarea id="data-row<?php echo $module_row;?>-<?php echo $language_id;?>" name="module[<?php echo $module_row?>][data][<?php echo $language_id?>]" cols="80" rows="3"><?php echo $module['data'][$language_id]?></textarea></p>
				<?php }?>
				</td>
				<td><input type="text" name="module[<?php echo $module_row?>][sort_order]" value="<?php echo $module['sort_order'];?>" size="3"></td>
				<td class="left"><a onclick="$('#module-row<?php echo $module_row; ?>').remove();" class="button"><?php echo $_['button_remove']; ?></a></td>
			  </tr>
            </tbody>
			<?php } ?>
			
			<?php $module_row++; ?>
			<?php } ?>
			<tfoot>
				<tr>
					<td class="right" colspan="4">
						<select id="type">
							<option value="banner"><?php echo $_['text_banner'];?></option>
							<option value="slideshow"><?php echo $_['text_slideshow'];?></option>
							<option value="product"><?php echo $_['text_product'];?></option>
							<option value="custom"><?php echo $_['text_custom'];?></option>
						</select>&nbsp;
						<a onclick="addModule();" class="button"><?php echo $_['button_add_module']; ?></a>
					</td>
				</tr>
			</tfoot>
          </table>
		  </div>
        </div>
      </form>
    </div>
  </div>
</div>
<script type="text/javascript" src="view/javascript/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="<?php echo ROOT;?>static/javascript/jquery/ui/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript"><!--
<?php foreach ($languages as $language) { ?>
CKEDITOR.replace('description<?php echo $language['language_id']; ?>', {
	filebrowserBrowseUrl: '<?php echo UA('common/filemanager'); ?>',
	filebrowserImageBrowseUrl: '<?php echo UA('common/filemanager'); ?>',
	filebrowserFlashBrowseUrl: '<?php echo UA('common/filemanager'); ?>',
	filebrowserUploadUrl: '<?php echo UA('common/filemanager/upload'); ?>',
	filebrowserImageUploadUrl: '<?php echo UA('common/filemanager/upload'); ?>',
	filebrowserFlashUploadUrl: '<?php echo UA('common/filemanager/upload'); ?>'
});
<?php } ?>

$('textarea[id^="data-row"]').each(function(i){
	CKEDITOR.replace($(this).attr('id'), {
		filebrowserBrowseUrl: '<?php echo UA('common/filemanager'); ?>',
		filebrowserImageBrowseUrl: '<?php echo UA('common/filemanager'); ?>',
		filebrowserFlashBrowseUrl: '<?php echo UA('common/filemanager'); ?>',
		filebrowserUploadUrl: '<?php echo UA('common/filemanager/upload'); ?>',
		filebrowserImageUploadUrl: '<?php echo UA('common/filemanager/upload'); ?>',
		filebrowserFlashUploadUrl: '<?php echo UA('common/filemanager/upload'); ?>'
	});
});
//--></script>

<script type="text/javascript"><!--
var module_row = <?php echo $module_row;?>;
function addModule() {
	var type = $('#type').val();
	switch(type) {
		case 'banner': addBanner();break;
		case 'slideshow': addSlideshow();break;
		case 'product': addProduct();break;
		case 'custom': addCustom();break;
	}
}

function addBanner() {
	var html = '';
	html += '<tbody id="module-row' + module_row + '">';
	html += '  <tr>';
	html += '	<td>';
	html += '	  <?php echo $_['text_banner'];?>';
	html += '	  <input type="hidden" name="module[' + module_row + '][type]" value="banner">';
	html += '	</td>';
	html += '	<td>';
	html += '	  <?php echo $_['text_banner']?> :';
	html += '	  <select name="module[' + module_row + '][data][banner_id]">';
	html += '	  <?php echo form_select_option($banners, 0, null, 'banner_id', 'name'); ?>';
	html += '	  </select>&nbsp;&nbsp;';
	html += '	  <?php echo $_['text_template']?> :';
	html += '	  <input type="text" name="module[' + module_row + '][data][template]">';
	html += '	</td>';
	html += '	<td><input type="text" name="module[' + module_row + '][sort_order]" value="0" size="3"></td>';
	html += '	<td class="left"><a onclick="$(\'#module-row' + module_row + '\').remove();" class="button"><?php echo $_['button_remove']; ?></a></td>';
	html += '  </tr>';
	html += '</tbody>';
	$('#modules tfoot').before(html);
	module_row++;
}

function addSlideshow() {
	var html = '';
	html += '<tbody id="module-row' + module_row + '">';
	html += '  <tr>';
	html += '	<td>';
	html += '	  <?php echo $_['text_slideshow'];?>';
	html += '	  <input type="hidden" name="module[' + module_row + '][type]" value="slideshow">';
	html += '	</td>';
	html += '	<td>';
	html += '	  <?php echo $_['text_banner']?> :';
	html += '	  <select name="module[' + module_row + '][data][banner_id]">';
	html += '	  <?php echo form_select_option($banners, 0, null, 'banner_id', 'name'); ?>';
	html += '	  </select>&nbsp;&nbsp;';
	html += '	  <?php echo $_['text_template']?> :';
	html += '	  <input type="text" name="module[' + module_row + '][data][template]">';
	html += '	</td>';
	html += '	<td><input type="text" name="module[' + module_row + '][sort_order]" value="0" size="3"></td>';
	html += '	<td class="left"><a onclick="$(\'#module-row' + module_row + '\').remove();" class="button"><?php echo $_['button_remove']; ?></a></td>';
	html += '  </tr>';
	html += '</tbody>';
	$('#modules tfoot').before(html);
	module_row++;
}

function addProduct() {
	var html = '';
	html += '<tbody id="module-row' + module_row + '">';
	html += '  <tr>';
	html += '	<td>';
	html += '	  <?php echo $_['text_product'];?>';
	html += '	  <input type="hidden" name="module[' + module_row + '][type]" value="product">';
	html += '	</td>';
	html += '	<td><p><?php echo $_['text_title'];?>: ';
	<?php foreach ($languages as $language_id => $language) { ?>
	html += '	<input type="text" name="module[' + module_row + '][data][title][<?php echo $language_id; ?>]" />';
	html += '	<img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" />';
	<?php } ?>
	html += '	  </p><p><?php echo $_['text_refid']?> :';
	html += '	  <input type="text" name="module[' + module_row + '][data][refid]">&nbsp;&nbsp;';
	html += '	  <?php echo $_['text_template']?> :';
	html += '	  <input type="text" name="module[' + module_row + '][data][template]"></p>';
	html += '	</td>';
	html += '	<td><input type="text" name="module[' + module_row + '][sort_order]" value="0" size="3"></td>';
	html += '<td class="left"><a onclick="$(\'#module-row' + module_row + '\').remove();" class="button"><?php echo $_['button_remove']; ?></a></td>';
	html += '  </tr>';
	html += '</tbody>';
	$('#modules tfoot').before(html);
	module_row++;
}

function addCustom() {
	var html = '';
	html += '<tbody id="module-row' + module_row + '">';
	html += '<tr>';
	html += '	<td>';
	html += '	  <?php echo $_['text_custom'];?>';
	html += '	  <input type="hidden" name="module[' + module_row + '][type]" value="custom">';
	html += '	</td>';
	html += '	<td valign="top">';
	<?php foreach ($languages as $language_id => $language) { ?>
	html += '	 <p><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" />';
	html += '	 <textarea id="data-row' + module_row + '-<?php echo $language_id;?>" name="module[' + module_row + '][data][<?php echo $language_id?>]" cols="80" rows="3"></textarea></p>';
	<?php }?>
	html += '	</td>';
	html += '	<td><input type="text" name="module[' + module_row + '][sort_order]" value="0" size="3"></td>';
	html += '	<td class="left"><a onclick="$(\'#module-row' + module_row + '\').remove();" class="button"><?php echo $_['button_remove']; ?></a></td>';
	html += ' </tr>';
	html += '</tbody>';
	$('#modules tfoot').before(html);
	
	<?php foreach ($languages as $language) { ?>
	CKEDITOR.replace('data-row' + module_row + '-<?php echo $language['language_id']; ?>', {
		filebrowserBrowseUrl: '<?php echo UA('common/filemanager'); ?>',
		filebrowserImageBrowseUrl: '<?php echo UA('common/filemanager'); ?>',
		filebrowserFlashBrowseUrl: '<?php echo UA('common/filemanager'); ?>',
		filebrowserUploadUrl: '<?php echo UA('common/filemanager/upload'); ?>',
		filebrowserImageUploadUrl: '<?php echo UA('common/filemanager/upload'); ?>',
		filebrowserFlashUploadUrl: '<?php echo UA('common/filemanager/upload'); ?>'
	});
	<?php } ?>

	module_row++;
}

$('#tabs a').tabs();
$('#languages a').tabs();
$('.date').datepicker({dateFormat: 'yy-mm-dd'});
//--></script>
<?php echo $footer; ?>